<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<title>Fill comparing table</title>
</head>
<body>
<div class="container">
	<h1>Fill the decision table</h1>
	<h1>Please, fill only above half of the table, the other half will fill automatically</h1>
	
	<form:form method="POST" commandName="tableForm"
		action="${pageContext.request.contextPath}/table/create">
		
		<h1>Compare criteria between each other</h1>
		
		<table border="1">

			<form:select path="tableList[0].operation">
				<form:options items="${tableList[0].operation}" />
			</form:select>
			<tbody>
				<tr>
					<th></th>
					<c:forEach var="cr_name" items="${criteria}">
						<th>${cr_name.name}</th>
					</c:forEach>

				</tr>
				<c:forEach var="cr_name" items="${criteria}" varStatus="i">
					<tr>
					<td>${cr_name.name}</td>
						<c:forEach var="cr_name2" items="${criteria}" varStatus="j">
						
							<c:choose >
								<c:when test="${i.index > j.index }">
									<td><input type="text" name="tableList[0].table[${i.index}][${j.index}]" value="0,0,0" readonly="true" /></td>
								</c:when>
							
								<c:when test="${i.index == j.index }">
									<td><input type="text" name="tableList[0].table[${i.index}][${j.index}]" value="1,1,1" readonly="true" /></td>
								</c:when>
								
								<c:when test="${i.index != j.index }">
									<td><form:input path="tableList[0].table[${i.index}][${j.index}]" /></td>
								</c:when>
							</c:choose>
						</c:forEach>

					</tr>

				</c:forEach>
				
			</tbody>
		</table><br/>
		<form:errors path="tableList[0]" cssStyle="color: red;" /><br/>
		
		
		<c:forEach var="cr_name" items="${criteria }" varStatus="k">
		
			<h1>Compare companies for criterion "${cr_name.name }"</h1>		
		
			<table border="1">

			<form:select path="tableList[${k.index+1}].operation">
				<form:options items="${tableList[k.index].operation}" />
			</form:select>
			<tbody>
				<tr>
					<th></th>
					<c:forEach var="firm" items="${firms}">
						<th>${firm.name}</th>
					</c:forEach>

				</tr>
				<c:forEach var="firm" items="${firms}" varStatus="i">
					<tr>
					<td>${firm.name}</td>
						<c:forEach var="firm1" items="${firms}" varStatus="j">
						
							<c:choose >
								<c:when test="${i.index > j.index }">
									<td><input type="text" name="tableList[${k.index+1}].table[${i.index}][${j.index}]" value="0,0,0" readonly="true" /></td>
								</c:when>
							
								<c:when test="${i.index == j.index }">
									<td><input type="text" name="tableList[${k.index+1}].table[${i.index}][${j.index}]" value="1,1,1" readonly="true" /></td>
								</c:when>
								
								<c:when test="${i.index != j.index }">
									<td><form:input path="tableList[${k.index+1}].table[${i.index}][${j.index}]" /></td>
								</c:when>
							</c:choose>
						</c:forEach>

					</tr>

				</c:forEach>
				
			</tbody>
		</table><br/>
		<form:errors path="tableList[${k.index+1}]" cssStyle="color: red;" /><br/>
		
		</c:forEach>
		
		<input type="submit" value="Calculate" />
	</form:form>
	<a href="${pageContext.request.contextPath}/">Home page</a>
</div>
</body>
</html>